﻿namespace Lzhdim.WinSrvMgr
{
    using Lzhdim.ProgramInstance;
    using System;
    using System.Diagnostics;
    using System.Runtime.InteropServices;
    using System.Windows.Forms;

    /// <summary>
    /// 程序类
    /// </summary>
    internal static class Program
    {
        /// <summary>
        /// 应用程序的主入口点
        /// </summary>
        [STAThread]
        private static void Main()
        {
            if (AppInstance.IsUniqueRunning())
            {
                Process process = AppInstance.GetAppProcess();

                ShowWindowAsync(process.MainWindowHandle, 9 | 1);
                SetForegroundWindow(process.MainWindowHandle);

                return;
            }

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            Application.Run(Windows.Instance.MainForm);
        }

        [DllImport("User32.dll")]
        private static extern bool SetForegroundWindow(IntPtr hWnd);

        [DllImport("User32.dll")]
        private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);
    }
}